package com.bank.view;

import com.bank.javabean.Account;
import com.bank.javabean.Detail;
import com.bank.service.UserService;
import com.bank.serviceimpl.UserServiceImpl;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Auther: Liu
 */
//用户页面
public class UserView {
    //跳转用户页面  需要将当前登录账号信息传入
    public static void view(Account account){
        UserService userService=new UserServiceImpl();
        //当前账号id
        int myId=account.getId();
        Scanner scInt = new Scanner(System.in);
        Scanner scString = new Scanner(System.in);
        System.out.println("======用户页面======");
        while (true) {
            System.out.println("请输入选择1-修改密码 2-查询个人信息 3-存款 4-取款 5-转账 6-查询交易信息 7-退出");
            int choose = scInt.nextInt();
            if(choose==1){
                System.out.println("请输入新的密码");
                String password= scString.nextLine();
                //调用用户服务修改密码方法
                userService.resetPassword(myId,password);
            }else if(choose==2){
                //调用用户服务根据id查询数据方法
                Account myInfo = userService.findMyInfo(myId);
                System.out.println(myInfo);
            }else if(choose==3){
                System.out.println("请输入存入金额");
                double money= scInt.nextDouble();
                //调用用户服务存款方法
                userService.deposit(account.getUsername(),money);
            }else if(choose==4){
                System.out.println("请输入取出金额");
                double money= scInt.nextDouble();
                //调用用户服务取款方法
                userService.withdrawal(account.getUsername(),money);
            }else if(choose==5){
                System.out.println("请输入转入账号");
                String tname = scString.nextLine();
                System.out.println("请输入转出金额");
                double money= scInt.nextDouble();
                //调用用户服务转账方法
                userService.transferMoney(account.getUsername(),tname,money);
            }else if(choose==6){
                //调用用户服务查询交易记录方法
                ArrayList<Detail> myDetail = userService.findMyDetail(account.getUsername());
                for (Detail detail : myDetail) {
                    System.out.println(detail);
                }
            }else{
                break;
            }
        }
    }
}

